﻿<html><body style='font-size:11px; color:#000000; background:#ffffff; '><pre>
<span style='color:#800000; font-weight:bold; '>private</span> <span style='color:#800000; font-weight:bold; '>void</span> convertToPdfButton_Click<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>object</span> sender<span style='color:#808030; '>,</span> EventArgs e<span style='color:#808030; '>)</span>
<span style='color:#800080; '>{</span>
    <span style='color:#696969; '>// Create a HTML to PDF converter object with default settings</span>
    HtmlToPdfConverter htmlToPdfConverter <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> HtmlToPdfConverter<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set license key received after purchase to use the converter in licensed mode</span>
    <span style='color:#696969; '>// Leave it not set to use the converter in demo mode</span>
    htmlToPdfConverter<span style='color:#808030; '>.</span>LicenseKey <span style='color:#808030; '>=</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed</span>
    <span style='color:#696969; '>// Set this property to 0 if you don't need to wait for such asynchcronous operations to finish</span>
    htmlToPdfConverter<span style='color:#808030; '>.</span>ConversionDelay <span style='color:#808030; '>=</span> <span style='color:#008c00; '>2</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>string</span> param1Name <span style='color:#808030; '>=</span> param1NameTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param1NameTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>param1</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>string</span> param1Value <span style='color:#808030; '>=</span> param1ValueTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param1ValueTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Value 1</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>string</span> param2Name <span style='color:#808030; '>=</span> param2NameTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param2NameTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>param2</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>string</span> param2Value <span style='color:#808030; '>=</span> param2ValueTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param2ValueTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Value 2</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>string</span> param3Name <span style='color:#808030; '>=</span> param3NameTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param3NameTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>param3</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>string</span> param3Value <span style='color:#808030; '>=</span> param3ValueTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param3ValueTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Value 3</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>string</span> param4Name <span style='color:#808030; '>=</span> param4NameTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param4NameTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>param4</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>string</span> param4Value <span style='color:#808030; '>=</span> param4ValueTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param4ValueTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Value 4</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>string</span> param5Name <span style='color:#808030; '>=</span> param5NameTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param5NameTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>param5</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>string</span> param5Value <span style='color:#808030; '>=</span> param5ValueTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? param5ValueTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>Value 5</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>string</span> urlToConvert <span style='color:#808030; '>=</span> urlTextBox<span style='color:#808030; '>.</span>Text<span style='color:#800080; '>;</span>

    <span style='color:#800000; font-weight:bold; '>if</span> <span style='color:#808030; '>(</span>postMethodRadioButton<span style='color:#808030; '>.</span>Checked<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        htmlToPdfConverter<span style='color:#808030; '>.</span>HttpPostFields<span style='color:#808030; '>.</span>Add<span style='color:#808030; '>(</span>param1Name<span style='color:#808030; '>,</span> param1Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        htmlToPdfConverter<span style='color:#808030; '>.</span>HttpPostFields<span style='color:#808030; '>.</span>Add<span style='color:#808030; '>(</span>param2Name<span style='color:#808030; '>,</span> param2Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        htmlToPdfConverter<span style='color:#808030; '>.</span>HttpPostFields<span style='color:#808030; '>.</span>Add<span style='color:#808030; '>(</span>param3Name<span style='color:#808030; '>,</span> param3Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        htmlToPdfConverter<span style='color:#808030; '>.</span>HttpPostFields<span style='color:#808030; '>.</span>Add<span style='color:#808030; '>(</span>param4Name<span style='color:#808030; '>,</span> param4Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        htmlToPdfConverter<span style='color:#808030; '>.</span>HttpPostFields<span style='color:#808030; '>.</span>Add<span style='color:#808030; '>(</span>param5Name<span style='color:#808030; '>,</span> param5Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
    <span style='color:#800000; font-weight:bold; '>else</span>
    <span style='color:#800080; '>{</span>
        Uri getMethodUri <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>new</span> Uri<span style='color:#808030; '>(</span>urlTextBox<span style='color:#808030; '>.</span>Text<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
                
        <span style='color:#800000; font-weight:bold; '>string</span> query <span style='color:#808030; '>=</span> getMethodUri<span style='color:#808030; '>.</span>Query<span style='color:#808030; '>.</span>Length <span style='color:#808030; '>></span> <span style='color:#008c00; '>0</span> ? <span style='color:#800000; '>"</span><span style='color:#0000e6; '>&amp;</span><span style='color:#800000; '>"</span> <span style='color:#808030; '>:</span> <span style='color:#800000; '>"</span><span style='color:#0000e6; '>?</span><span style='color:#800000; '>"</span> <span style='color:#808030; '>+</span> String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>{0}={1}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> param1Name<span style='color:#808030; '>,</span> param1Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        query <span style='color:#808030; '>+</span><span style='color:#808030; '>=</span> String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>&amp;{0}={1}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> param2Name<span style='color:#808030; '>,</span> param2Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        query <span style='color:#808030; '>+</span><span style='color:#808030; '>=</span> String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>&amp;{0}={1}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> param3Name<span style='color:#808030; '>,</span> param3Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        query <span style='color:#808030; '>+</span><span style='color:#808030; '>=</span> String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>&amp;{0}={1}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> param4Name<span style='color:#808030; '>,</span> param4Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        query <span style='color:#808030; '>+</span><span style='color:#808030; '>=</span> String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>&amp;{0}={1}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> param5Name<span style='color:#808030; '>,</span> param5Value<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        urlToConvert <span style='color:#808030; '>=</span> urlTextBox<span style='color:#808030; '>.</span>Text <span style='color:#808030; '>+</span> query<span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
            
    Cursor <span style='color:#808030; '>=</span> Cursors<span style='color:#808030; '>.</span>WaitCursor<span style='color:#800080; '>;</span>

    <span style='color:#696969; '>// Convert HTML to PDF using the settings above</span>
    <span style='color:#800000; font-weight:bold; '>string</span> outPdfFile <span style='color:#808030; '>=</span> @<span style='color:#800000; '>"</span><span style='color:#0000e6; '>DemoAppFiles\Output\HTML_to_PDF\GET_and_POST.pdf</span><span style='color:#800000; '>"</span><span style='color:#800080; '>;</span>
    <span style='color:#800000; font-weight:bold; '>try</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// Convert the HTML page to a PDF document in a memory buffer</span>
        <span style='color:#800000; font-weight:bold; '>byte</span><span style='color:#808030; '>[</span><span style='color:#808030; '>]</span> outPdfBuffer <span style='color:#808030; '>=</span> htmlToPdfConverter<span style='color:#808030; '>.</span>ConvertUrl<span style='color:#808030; '>(</span>urlToConvert<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

        <span style='color:#696969; '>// Write the memory buffer in a PDF file</span>
        System<span style='color:#808030; '>.</span>IO<span style='color:#808030; '>.</span>File<span style='color:#808030; '>.</span>WriteAllBytes<span style='color:#808030; '>(</span>outPdfFile<span style='color:#808030; '>,</span> outPdfBuffer<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
    <span style='color:#800000; font-weight:bold; '>catch</span> <span style='color:#808030; '>(</span>Exception ex<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        <span style='color:#696969; '>// The HTML to PDF conversion failed</span>
        MessageBox<span style='color:#808030; '>.</span>Show<span style='color:#808030; '>(</span>String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>HTML to PDF Error. {0}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> ex<span style='color:#808030; '>.</span>Message<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
        <span style='color:#800000; font-weight:bold; '>return</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
    <span style='color:#800000; font-weight:bold; '>finally</span>
    <span style='color:#800080; '>{</span>
        Cursor <span style='color:#808030; '>=</span> Cursors<span style='color:#808030; '>.</span>Arrow<span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>

    <span style='color:#696969; '>// Open the created PDF document in default PDF viewer</span>
    <span style='color:#800000; font-weight:bold; '>try</span>
    <span style='color:#800080; '>{</span>
        System<span style='color:#808030; '>.</span>Diagnostics<span style='color:#808030; '>.</span>Process<span style='color:#808030; '>.</span>Start<span style='color:#808030; '>(</span>outPdfFile<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
    <span style='color:#800000; font-weight:bold; '>catch</span> <span style='color:#808030; '>(</span>Exception ex<span style='color:#808030; '>)</span>
    <span style='color:#800080; '>{</span>
        MessageBox<span style='color:#808030; '>.</span>Show<span style='color:#808030; '>(</span>String<span style='color:#808030; '>.</span>Format<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>Cannot open created PDF file '{0}'. {1}</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> outPdfFile<span style='color:#808030; '>,</span> ex<span style='color:#808030; '>.</span>Message<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
    <span style='color:#800080; '>}</span>
<span style='color:#800080; '>}</span>
</pre>
</body>
</html>